import socket
import sys
import time

HOST,PORT = "192.168.43.55",19984

def Image_Send(id):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))

    # 包头标志
    arrBuf = bytearray(b'\xff\xaa\xff\xaa')

    # 以二进制方式读取图片
    picData = open('data/images/1.jpg', 'rb')
    picBytes = picData.read()

    # 图片大小
    picSize = len(picBytes)

    # 车牌号
    id_len = len(id)
    idb = bytearray(id, encoding="utf8")




    #时间数据长度
    time=Time_Send()
    timeb=bytearray(time, encoding="utf8")
    timeSize=len(timeb)

    #时间字节告知
    timelen = timeSize
    print(timelen)

    # 转为二进制
    # timeb = bytearray(time, 'utf-8')


    # 数据体长度 = guid大小(固定) + 图片大小
    datalen = 64 + picSize + timeSize + id_len

    # 组合数据包
    arrBuf += bytearray(id_len.to_bytes(1, byteorder='little'))
    arrBuf += bytearray(timelen.to_bytes(1, byteorder='little'))
    arrBuf += bytearray(datalen.to_bytes(4, byteorder='little'))
    guid = 23458283482894382928948
    arrBuf += bytearray(guid.to_bytes(64, byteorder='little'))
    arrBuf += idb
    arrBuf += timeb
    arrBuf += picBytes

    sock.sendall(arrBuf)
    sock.close()


def Time_Send():
    return time.strftime("%Y-%m-%d %H:%M %S",time.localtime(time.time()))


def license_plate_number_Send():

   return

def Iclient(id):
    Image_Send(id)

if __name__ == '__main__':
    # t = Time_Send()
    # print(t)
    id = "请查看图片"
    Image_Send(id)

